|
|
|
|
|
|
|
The method, clickedModifyBtn, invokes theBusiness.createMemento before the modify transaction even begins. The clickedModifyBtn method is invoked by the Modify button (code named cmdModify) on the form. The method invocation looks like the following: |
|
|
|
|
|
|
|
|
Private Sub cmdModify_Click()
theFormController.clickedModifyBtn
End Sub |
|
|
|
|
|
|
|
|
The global declarations for theBusiness and theFormController objects are in the General Declarations of the sample code module, modMain, as follows: |
|
|
|
|
|
|
|
|
Global theBusiness As New Business
Global theFormController As New FormController |
|
|
|
|
|
|
|
|
After the Memento is created, you allow the user to make modifications. When the user decides that he or she doesn't want to keep the changes, theForm invokes the clickedUndoBtn method. |
|
|
|
|
|
|
|
|
The clickedUndoBtn method invokes the setMemento method of theBusiness, passing it back the object, theBusinessMemento, created by theBusiness.createMemento. The setMemento method of theBusiness returns theBusiness back to its previous state. This is important to do before setting theForm.Text1 to the MyName property of theBusiness. |
|
|
|
|
|
|
|
|
The object, theBusiness, has two methods that are important for undo operations: createMemento() and setMemento(). Listing 11.6 shows the code for the two methods. |
|
|
|
|
|
|
|
|
LISTING 11.6. THEcreateMementoANDsetMementoMETHODS. |
|
|
|
 |
|
|
|
|
1: Public Function createMemento() As BusinessMemento
2: arrMemento = Array(theBusiness.MyName)
3: Set theBusinessMemento = New BusinessMemento
4: theBusinessMemento.setState arrMemento
5: Set createMemento = theBusinessMemento
6: End Function
7:
8: Public Sub setMemento(argMemento As BusinessMemento)
9: Dim PreviousState
10: PreviousState = argMemento.getState
11: MyName = PreviousState(eMemento.bMyName)
12: PreviousState =
13: End Sub
14:
15: 'Declarations
16: 'local variable(s) to hold property value(s)
17: Private mvarMyName As String 'local copy
18:
19: Private arrMemento
20:
|
|
|
|
|
|